<template>
    <div>
        <h1>登录页面</h1>
    </div>
    <table>
        <tr>
            <td>用户名</td>
            <td>
                <input type="text" v-model="data.uname">
            </td>
        </tr>
        <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="data.upwd">
            </td>
        </tr>
        <tr>
                <td></td>
                <td><input type="button" value="登录" @click="login"></td>
            </tr>
    </table>
</template>

<script setup lang="ts">
import axios from 'axios';
import {ref} from 'vue';
import { useRouter } from 'vue-router';
const router=useRouter();
const data=ref({
    uname:'',
    upwd:''
})
const login=()=>{
    axios.get("/api/User/Login",{params:data.value}).then(res=>{
        if(res.data.Id==-1)
        {
            alert('用户名错误')
            return;
        }
        else if(res.data.Id==-2)
        {
            alert('密码错误')
            return;
        }
        else
        {
            alert('登录成功')
            sessionStorage.setItem('用户名',data.value.uname)
            sessionStorage.setItem('密码',data.value.upwd)
            router.push('/');
        }
    })
}





</script>

<style scoped>

</style>